using System;

namespace SemanticEngine.Apml
{
	public class Source : ItemBase
	{

		#region Properties

		private Uri _Url;

		public Uri Url
		{
			get { return _Url; }
			set { _Url = value; }
		}

		private string _Name;

		public string Name
		{
			get { return _Name; }
			set { _Name = value; }
		}

		private string _ContentType;

		public string ContentType
		{
			get { return _ContentType; }
			set { _ContentType = value; }
		}

		private Author _Author;

		public Author Author
		{
			get { return _Author; }
			set { _Author = value; }
		}

		private DataType _DataType;

		public DataType DataType
		{
			get { return _DataType; }
			set { _DataType = value; }
		}

		#endregion

		#region Methods

		public void AddAuthor(string name)
		{
			Author = new Author(name);
		}

		public void AddAuthor(string name, double rank)
		{
			Author = new Author(name, rank);
		}

		public void AddAuthor(string name, double rank, string from)
		{
			Author = new Author(name, rank, from);
		}

		public override string ToString()
		{
			return Name;
		}

		protected override void Validate()
		{
			base.Validate();
			AddRule("Name", "Name of a Source must be specified", string.IsNullOrEmpty(Name));
			AddRule("Author", Author.ValidationMessage, Author != null && !Author.IsValid);
			AddRule("Url", "The Url of a Source must be set", Url == null);
			AddRule("Url", "The Url of a Source must be absolute", !Url.IsAbsoluteUri);
		}

		#endregion

	}
}
